/*
 * event.c
 *
 *  Created on: 2017年2月24日
 *      Author: chen
 */


/* Includes ------------------------------------------------------------------*/
#include "fsl_debug_console.h"
#include "fsl_ftm.h"
#include "fsl_pit.h"

#include "peripherals.h"

#include "pit.h"
#include "motor.h"
#include "ov7725.h"

/* Variables -----------------------------------------------------------------*/
volatile uint32_t loop_counter = 0U;
volatile bool PIT_ReadyFlag = false;

extern mSpeed_t motor;

/**
  * @brief  PIT中断服务程序
  * @retval none
  */
void PIT0_IRQHandler(void)
{
    /* Clear pit interrupt flag */
    PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, kPIT_TimerFlag);
    
    /* Delay 函数服务程序，负责延时计次 */
    Delay_ISR_Handle();

    loop_counter++;
    if (loop_counter > 1000U) /* 1s. */
    {
        loop_counter = 0U;
        PIT_ReadyFlag = true;
        /* 获取转速信息 */
        Motor_GetCnt(&motor);
    }

    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}

/**
  * @brief  PORTC中断服务程序（摄像头）
  * @retval none
  */
void CAM_INTERRUPT_IRQHANDLER(void)
{
    /* 摄像头中断回调 */
    CAM_ISR_Handle();
}

/**
  * @brief  HardFault中断服务程序
  * @retval none
  */
void HardFault_Handler(void)
{
    /* HardFault指示（三灯全亮） */
    //TODO
    while (1)
    {
    }
}
